//
//  EnterTipView.m
//  YouinRTCDemo
//
//  Created by 潘欣 on 2023/7/5.
//

#import "EnterTipView.h"

@implementation EnterTipView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.btnTitle = [[UIButton alloc] initWithFrame:self.bounds];
//        self.btnTitle.textAlignment = NSTextAlignmentCenter;
        self.btnTitle.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [self.btnTitle setTitleColor:[UIColor whiteColor] forState:0];
//        self.btnTitle.backgroundColor = rgba(25, 148, 255, 1);
        self.btnTitle.layer.cornerRadius = 13;
        self.btnTitle.clipsToBounds = YES;
        [self addSubview:self.btnTitle];
        
        


      
        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.colors = @[(__bridge id)[UIColor colorWithRed:1.0 green:0.67 blue:0.0 alpha:1.0].CGColor,
                                 (__bridge id)[UIColor colorWithRed:1.0 green:0.38 blue:0.0 alpha:0.7].CGColor];
        gradientLayer.startPoint = CGPointMake(1.0, 0.5);
        gradientLayer.endPoint = CGPointMake(0.0, 0.5);

        // 设置渐变层的大小和位置
//        gradientLayer.frame = self.bounds;
        gradientLayer.frame = CGRectMake(-10, 0, self.bounds.size.width + 20, self.bounds.size.height);

        // 将渐变层添加到 label 上
        [self.btnTitle.layer addSublayer:gradientLayer];
        [self.btnTitle bringSubviewToFront:self.btnTitle.titleLabel];

        // 设置自动布局约束
        self.btnTitle.translatesAutoresizingMaskIntoConstraints = NO;
        [NSLayoutConstraint activateConstraints:@[
            [self.btnTitle.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:8.0],
            [self.btnTitle.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-8.0],
            [self.btnTitle.topAnchor constraintEqualToAnchor:self.topAnchor constant:8.0],
            [self.btnTitle.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-8.0],
        ]];
    }
    return self;
}
@end
